package events

import (
	"time"
)

// 领域事件基础接口
type DomainEvent interface {
	EventID() string
	EventType() string
	OccurredOn() time.Time
	AggregateID() string
}

// 交易创建事件
type TransactionCreatedEvent struct {
	ID           string          `json:"id"`
	Type         string          `json:"type"`
	OccurredTime time.Time       `json:"occurred_on"`
	Transaction  TransactionData `json:"transaction"`
}

// 交易数据
type TransactionData struct {
	TransactionID string    `json:"transaction_id"`
	UserID        string    `json:"user_id"`
	Amount        int64     `json:"amount"` // 分为单位
	Currency      string    `json:"currency"`
	Status        string    `json:"status"`
	CreatedAt     time.Time `json:"created_at"`
	MerchantID    string    `json:"merchant_id"`
	OrderNo       string    `json:"order_no"`
}

func (e TransactionCreatedEvent) EventID() string {
	return e.ID
}

func (e TransactionCreatedEvent) EventType() string {
	return "transaction.created"
}

func (e TransactionCreatedEvent) OccurredOn() time.Time {
	return e.OccurredTime
}

func (e TransactionCreatedEvent) AggregateID() string {
	return e.Transaction.TransactionID
}

// 交易状态变更事件
type TransactionStatusChangedEvent struct {
	ID            string    `json:"id"`
	Type          string    `json:"type"`
	OccurredTime  time.Time `json:"occurred_on"`
	TransactionID string    `json:"transaction_id"`
	OldStatus     string    `json:"old_status"`
	NewStatus     string    `json:"new_status"`
	Amount        int64     `json:"amount"`
	UserID        string    `json:"user_id"`
}

func (e TransactionStatusChangedEvent) EventID() string {
	return e.ID
}

func (e TransactionStatusChangedEvent) EventType() string {
	return "transaction.status_changed"
}

func (e TransactionStatusChangedEvent) OccurredOn() time.Time {
	return e.OccurredTime
}

func (e TransactionStatusChangedEvent) AggregateID() string {
	return e.TransactionID
}
